package com.haidechizi.util.lock.configuration;

import com.haidechizi.util.lock.aop.DistributeLockAop;
import com.haidechizi.util.lock.impl.CuratorDistributeLock;
import com.haidechizi.util.lock.impl.RedissonDistributeLock;
import org.apache.curator.framework.recipes.locks.InterProcessLock;
import org.redisson.spring.starter.RedissonAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * @author: wangdejun
 * @create: 2019-11-13 10:02
 **/

@Configuration
@EnableAspectJAutoProxy
@AutoConfigureAfter(RedissonAutoConfiguration.class)
public class DistributeLockConfiguration {

    @Bean
    public DistributeLockAop distributeLockAop() {
        return new DistributeLockAop();
    }

    @Bean
    @ConditionalOnBean(CuratorConfiguration.class)
    public CuratorDistributeLock curatorDistributeLock() {
        return new CuratorDistributeLock();
    }

    @Bean
    @ConditionalOnBean(RedissonAutoConfiguration.class)
    public RedissonDistributeLock redissonDistributeLock() {
        return new RedissonDistributeLock();
    }
}
